home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / nextgo23.taz / nextgo23 / NeXTGo / suicide.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1.3 KB  |  58 lines

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4. #define BLACKSTONE 2
  5.  
  6. extern unsigned char p[19][19], l[19][19];
  7. extern int currentStone, opposingStone, MAXX, MAXY;
  8. extern int lib;
  9. extern int blackCapturedKoI, blackCapturedKoJ, whiteCapturedKoI, whiteCapturedKoJ;  /* piece captured */
  10. extern void countlib(int, int, int);
  11. extern void eval(int);
  12.  
  13. int suicide(int i, int j)
  14. /* check for suicide move of opponent at p[i][j] */
  15. {
  16.  int m, n, k, uik, ujk;
  17.  
  18. /* check liberty of new move */
  19.  lib = 0;
  20.  countlib(i, j, currentStone);
  21.  if (lib == 0)
  22. /* new move is suicide then check if kill my pieces and Ko possibility */
  23.    {
  24. /* assume alive */
  25.     p[i][j] = currentStone;
  26.  
  27. /* check opponent pieces */
  28.     eval(opposingStone);
  29.     k = 0;
  30.  
  31.     for (m = 0; m < MAXX; m++)
  32.       for (n = 0; n < MAXY; n++)
  33. /* count pieces that will be killed */
  34.     if ((p[m][n] == opposingStone) && !l[m][n]) ++k;
  35.  
  36.     if (currentStone == BLACKSTONE) {
  37.       uik = blackCapturedKoI;
  38.       ujk = blackCapturedKoJ;
  39.     } else {
  40.       uik = whiteCapturedKoI;
  41.       ujk = whiteCapturedKoJ;
  42.     }
  43.     if ((k == 0) || (k == 1 && ((i == uik) && (j == ujk))))
  44. /* either no effect on my pieces or an illegal Ko take back */
  45.       {
  46.        p[i][j] = EMPTY;   /* restore to open */
  47.        return 1;
  48.       }
  49.     else
  50. /* good move */
  51.       return 0;
  52.    }
  53.  else
  54. /* valid move */
  55.    return 0;
  56. }  /* end suicide */
  57.  
  58.